<?php


namespace app\cms\home\api\merchant;

use app\cms\authCallBack\merchant;
use app\cms\dto\merchant\merchantLicenseInfo;
use app\cms\model\merchant\merchantLicenseModel;
use iflow\auth\lib\authAnnotation;
use iflow\Response;
use iflow\Router\Controller;
use iflow\Router\implement\Request\{ GetMapping, PostMapping, DeleteMapping };

#[Controller('%cmsHome%/merchant_license')]
class merchantLicense
{

    /**
     * 获取商户证书列表
     * @param string $merchant_license_id
     * @param int $license_type
     * @param int $license_review_type
     * @param string $merchant_name
     * @return Response
     */
    #[GetMapping]
    #[authAnnotation('merchant_license', '*', merchant::class. "@userMerchantExists")]
    public function get(
        // 许可id
        string $merchant_license_id = "",
        // 许可类型
        int $license_type = -1,
        // 许可审核状态
        int $license_review_type = -1,
        // 商户名称
        string $merchant_name = ""
    ): Response {
        return (new merchantLicenseModel()) -> licenseList(
            session('merchant')['merchant_id'],
            $merchant_license_id,
            $license_type,
            $license_review_type,
            $merchant_name
        );
    }

    /**
     * 更新商户信息
     * @param merchantLicenseInfo $merchantLicenseInfo
     * @param string $type
     * @return Response
     */
    #[PostMapping]
    #[authAnnotation('merchant_license', '*', merchant::class. "@userMerchantExists")]
    public function update(merchantLicenseInfo $merchantLicenseInfo, string $type = ""): Response
    {
        return (new merchantLicenseModel()) -> updateLicense($merchantLicenseInfo, $type);
    }

    /**
     * 添加证书
     * @param merchantLicenseInfo $merchantLicenseInfo
     * @return Response
     */
    #[PostMapping]
    #[authAnnotation('merchant_license', '*', merchant::class. "@userMerchantExists")]
    public function create(merchantLicenseInfo $merchantLicenseInfo): Response
    {
        return (new merchantLicenseModel()) -> createLicense($merchantLicenseInfo);
    }

    /**
     * 删除证书
     * @param string $merchant_license_id
     * @return Response
     */
    #[DeleteMapping('delete/<?:merchant_license_id>')]
    #[authAnnotation('merchant_license', '*', merchant::class. "@userMerchantExists")]
    public function delete(string $merchant_license_id): Response
    {
        return (new merchantLicenseModel()) -> deleteLicense(
            session('merchant')['merchant_id'],
            $merchant_license_id
        );
    }
}